import com.My.demo.UserSevers;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-07-16
 * Time: 17:03
 */
public class APP {
    public static void main(String[] args) {
        //得到上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");

        //获取bean
        //用法1: 根据名称获取Bean对象
        UserSevers userSevers = (UserSevers) context.getBean("User");

        //用法2: 根据类型获取Bean对象 --> 可能会出问题:当同一个类型注入到Spring声明多次的情况下,使用这种方法就会报错!!!
        //UserSevers userSevers1 = context.getBean(UserSevers.class);

        //用法3: 根据名称+类型获取Bean对象
        //UserSevers userSevers2 = context.getBean("user2",UserSevers.class);

        //使用bean
        userSevers.sayHi();
    }
}
